﻿#ifndef IMAGEWIDGET_H
#define IMAGEWIDGET_H

#include <QLabel>
#include <QImage>
#include <QWheelEvent>
#include <QMouseEvent>
#include <QPointF>

class ImageWidget : public QLabel
{
	Q_OBJECT
public:
	explicit ImageWidget(QWidget* parent = nullptr);
	bool loadImage(const QString& path);
	void zoomIn();
	void zoomOut();
	void resetZoom();

signals:
	void pixelPositionChanged(const QString& info);

protected:
	void wheelEvent(QWheelEvent* event) override;
	void mouseMoveEvent(QMouseEvent* event) override;
	void paintEvent(QPaintEvent* event) override;
	void mousePressEvent(QMouseEvent* event) override;
	void mouseReleaseEvent(QMouseEvent* event) override;

private:
	QImage originalImage;  // 原始图片
	QImage displayImage;   // 当前显示的图片
	double scaleFactor = 1.0;
	const double zoomStep = 0.1;  // 每次缩放10%

	QPoint m_dragOffset = QPoint(0, 0);
	bool m_dragging = false;
	QPoint m_lastDragPos;

	void updateDisplayImage();
	QPointF mapToImage(const QPoint& pos);
};

#endif // IMAGEWIDGET_H
